//
//  RentCell.m
//  ZhuanZuBao
//
//  Created by bchy on 2020/8/28.
//  Copyright © 2020 戴伟. All rights reserved.
//

#import "RentCell.h"
#import "RentModel.h"
#import "TTGTextTagCollectionView.h"
@interface RentCell ()

@property (weak, nonatomic) IBOutlet UIImageView *coverImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *communityLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;

@property (nonatomic, strong) TTGTextTagCollectionView *tagView;


@end

@implementation RentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    _coverImageView.layer.masksToBounds = YES;
    _coverImageView.layer.cornerRadius = 4;
    self.tagView = [[TTGTextTagCollectionView alloc] initWithFrame:CGRectMake(108, 54, DEVICE_SCREEN_WIDTH-138, 26)];
    [self.contentView addSubview:self.tagView];
    self.tagView.backgroundColor = [UIColor whiteColor];
    self.tagView.scrollDirection = TTGTagCollectionScrollDirectionHorizontal;
    
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"RentCell";
    RentCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:ID owner:self options:nil] lastObject];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(void)setRent:(RentModel *)rent{
    _rent = rent;
    
    [_coverImageView sd_setImageWithURL:[NSURL URLWithString:rent.cover]];
    _titleLabel.text = rent.title;
    _priceLabel.text = rent.price;
    _communityLabel.text = [NSString stringWithFormat:@"%@ %@",rent.district, rent.community];
    _detailLabel.text = [NSString stringWithFormat:@"%@ %ld㎡",rent.houseType, rent.area];
    NSArray *arr = [rent.tags componentsSeparatedByString:@","];
    NSMutableArray *tagArr = [NSMutableArray array];
    for (int i = 0; i< arr.count && i<3; i++) {
        [tagArr addObject:arr[i]];
    }
    [self.tagView removeAllTags];
    TTGTextTagConfig *config = [[TTGTextTagConfig alloc] init];
    config.textColor = BLACKTEXTCOLOR;
    config.shadowOpacity = 0;
    config.cornerRadius = 0;
    config.selectedCornerRadius = 0;
    config.extraSpace = CGSizeMake(10, 6);
    config.backgroundColor = [UIColor colorWithHexString:@"#F2F7F9" andAlpha:1];
    config.textColor = [UIColor colorWithHexString:@"#8BB7E9" andAlpha:1];
    config.textFont = [UIFont systemFontOfSize:13];
    config.selectedTextColor = [UIColor colorWithHexString:@"#8BB7E9" andAlpha:1];
    config.selectedBackgroundColor = [UIColor colorWithHexString:@"#F2F7F9" andAlpha:1];
    
    [self.tagView addTags:tagArr withConfig:config];
    
}

@end
